import qs from 'qs';
import storage from '@/common/storage';

const install = (Vue, vm) => {
    // 此为自定义配置参数，具体参数见上方说明
    Vue.prototype.$u.http.setConfig({
        baseUrl: 'https://www.hesongzhineng.com/whisper',
        loadingText: '努力加载中~',
        loadingTime: 800,
    });

    Vue.prototype.$u.http.interceptor.request = (config) => {
        // console.log(config);
        const params = {
            c: 300,
            y: 'PLAYER',
            t: new Date().getTime(),
            uid: storage.get('uid') || '',
        };
        config.url = `${config.url}?${qs.stringify(params)}`;
        return config;
    };

    Vue.prototype.$u.http.interceptor.response = (res) => {
        if (res.code === 10000) {
            return res.data;
        } else {
            uni.showToast({
                title: res.message,
                icon: 'none',
                duration: 3000,
            });
            return {
                status: -1,
                msg: res.message,
            };
        }
    };
};

export default {
    install,
};
